#include <iostream>
using namespace std;

class A{
	virtual void foo(void) {} 
};
class B:public A{
	void foo (void) {}
};
class C:public A{
	void foo (void) {}
};

int main (void)
{
	B b;
	A *pa = &b; //向上造型 
	//向下造型 安全
	//B* pb = static_cast <B*> (pa);
	//C* pc = static_cast <C*> (pa); //危险
	
	B* pb = dynamic_cast <B*> (pa); //安全
	//null 表示失败
	C* pc = dynamic_cast <C*> (pa);
	cout << "pa=" << pa << endl;
	cout << "pb=" << pb << endl;
	cout << "pc=" << pc << endl;

	A& ra = b;
	C& rc = dynamic_cast<C&> (ra);//危险
	return 0;
}
